package com.neardrug.controller;

import com.neardrug.entity.patent;
import com.neardrug.common.Result;
import com.neardrug.controller.dto.patentPageDto;
import com.neardrug.services.patentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author rui
 * @ClassName: patentController
 * @create 2023-06-28 16:48
 */

//@Api(tags = "专利")
//@RestController
//@RequestMapping("/patent")
public class patentController {
    @Resource
    private patentService patentService;

    @ApiOperation("查询所有专利")
    @GetMapping
    public Result findAll() {
        return Result.success(patentService.findAll());
    }

    @ApiOperation("根据类型查找")
    @PostMapping("/type")
    public Result findByType(@RequestBody patentPageDto patentPageDto) {
        int pageNum = (patentPageDto.getPageNum() - 1) * patentPageDto.getPageSize();
        int pageSize = patentPageDto.getPageSize();
        String[] types = patentPageDto.getTypes();

        Map<String, Object> map = new HashMap<>();
        Integer total = patentService.selectTotal(types);
        List<patent> patents = patentService.findByType(types, pageNum, pageSize);

        map.put("total", total);
        map.put("data", patents);
        return Result.success(map);
    }
}
